package com.ruoyi.web.controller.basicInformation;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.basicInformation.vo.TChangeShiftsVo;
import com.ruoyi.system.basicInformation.bo.TChangeShiftsQueryBo;
import com.ruoyi.system.basicInformation.bo.TChangeShiftsAddBo;
import com.ruoyi.system.basicInformation.bo.TChangeShiftsEditBo;
import com.ruoyi.system.basicInformation.service.ITChangeShiftsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 交接班记录Controller
 * 
 * @author ruoyi
 * @date 2021-05-19
 */
@Api(value = "交接班记录控制器", tags = {"交接班记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/basicInformation/shifts")
public class TChangeShiftsController extends BaseController {

    private final ITChangeShiftsService iTChangeShiftsService;

    /**
     * 查询交接班记录列表
     */
    @ApiOperation("查询交接班记录列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:shifts:list')")
    @GetMapping("/list")
    public TableDataInfo<TChangeShiftsVo> list(TChangeShiftsQueryBo bo) {
        startPage();
        List<TChangeShiftsVo> list = iTChangeShiftsService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出交接班记录列表
     */
    @ApiOperation("导出交接班记录列表")
    @PreAuthorize("@ss.hasPermi('basicInformation:shifts:export')")
    @Log(title = "交接班记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TChangeShiftsVo> export(TChangeShiftsQueryBo bo) {
        List<TChangeShiftsVo> list = iTChangeShiftsService.queryList(bo);
        ExcelUtil<TChangeShiftsVo> util = new ExcelUtil<TChangeShiftsVo>(TChangeShiftsVo.class);
        return util.exportExcel(list, "交接班记录");
    }

    /**
     * 获取交接班记录详细信息
     */
    @ApiOperation("获取交接班记录详细信息")
    @PreAuthorize("@ss.hasPermi('basicInformation:shifts:query')")
    @GetMapping("/{id}")
    public AjaxResult<TChangeShiftsVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTChangeShiftsService.queryById(id));
    }

    /**
     * 新增交接班记录
     */
    @ApiOperation("新增交接班记录")
    @PreAuthorize("@ss.hasPermi('basicInformation:shifts:add')")
    @Log(title = "交接班记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TChangeShiftsAddBo bo) {
        return toAjax(iTChangeShiftsService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改交接班记录
     */
    @ApiOperation("修改交接班记录")
    @PreAuthorize("@ss.hasPermi('basicInformation:shifts:edit')")
    @Log(title = "交接班记录", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TChangeShiftsEditBo bo) {
        return toAjax(iTChangeShiftsService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除交接班记录
     */
    @ApiOperation("删除交接班记录")
    @PreAuthorize("@ss.hasPermi('basicInformation:shifts:remove')")
    @Log(title = "交接班记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTChangeShiftsService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
